/**********************************************************************
 *** *                                                            * ***
 *** *  Copyright (c) 2013 Harmonia Holdings Group LLC            * ***
 *** *                                                            * ***
 *** * Permission is hereby granted to use, modify, copy, and     * ***
 *** * distribute this software and its documentation for any     * ***
 *** * purpose only without profit, provided that the above       * ***
 *** * Copyright Notice appears in all copies and that both the   * ***
 *** * Copyright Notice and this Permission Notice appears in     * ***
 *** * every copy of supporting documentation.  No title to nor   * ***
 *** * ownership of the software is transferred hereby.  The name * ***
 *** * of Harmonia Holdings Group LLC shall not be used in        * ***
 *** * advertising or publicity related to the distribution of    * ***
 *** * the software without specific, written, prior permission.  * ***
 *** * This software is provided as-delivered without expressed   * ***
 *** * or implied warranty.  Harmonia Holdings Group LLC          * ***
 *** * makes no representation about the suitability of this      * ***
 *** * software for any purpose and accepts no responsibility for * ***
 *** * its use.                                                   * ***
 *** *                                                            * ***
 *** ************************************************************** ***
 *** *                                                            * ***
 *** * This program is free software; you can redistribute it     * ***
 *** * and/or modify it under the terms of the GNU General Public * ***
 *** * License as published by the Free Software Foundation;      * ***
 *** * either version 2 of the License, or (at your option) any   * ***
 *** * later version.                                             * ***
 *** *                                                            * ***
 *** * This program is distributed in the hope that it will be    * ***
 *** * useful, but WITHOUT ANY WARRANTY; without even the implied * ***
 *** * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR    * ***
 *** * PURPOSE.  See the GNU General Public License for more      * ***
 *** * details.                                                   * ***
 *** *                                                            * ***
 *** * You should have received a copy of the GNU General Public  * ***
 *** * License along with this program; if not, write to the Free * ***
 *** * Software Foundation, Inc., 51 Franklin Street, Fifth       * ***
 *** * Floor, Boston, MA 02110-1301, USA.                         * ***
 *** *                                                            * ***
 *** * For more information: http://www.gnu.org/licenses/gpl.html * ***
 *** *                                                            * ***
 **********************************************************************/
package org.etexascode.interrep.datamodel;
import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.bind.annotation.XmlTransient;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import org.etexascode.interrep.datamodel.utils.UtilsStringOnModel;

/**
 * The signal manager model.
 * @author jrutherford
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name="SignalManger")
@XmlSeeAlso(value=SignalIndication.class)
public class SignalManager implements Serializable {
	/** Serial ID. */
	@XmlTransient
	private static final long serialVersionUID = 2786568932989827369L;
	
	/** The list of signals. */
	@XmlElementWrapper(name="signals")
	@XmlElement
	private List<SignalIndication> signals;
	
	
	/** Constructor. */
	public SignalManager() {
		signals = new LinkedList<SignalIndication>();
	}
	
	/**
	 * Adds a SignalIndication to the list.
	 * @param signal The new SignalIndication.
	 */
	public void addSignal(SignalIndication signal) {
		signals.add(signal);
	}
	
	/** String representation. */
	@Override
	public String toString() {
		StringBuilder ret = new StringBuilder();
		
		UtilsStringOnModel.addList(ret, signals, "signals");
		
		return ret.toString();
	}
	
	/** Check if 2 signal managers are equal. */
	@Override
	public boolean equals(Object obj) {
		if(obj instanceof SignalManager){
			SignalManager sm = (SignalManager) obj;
			return this.toString().equals(sm.toString());
		} else {
			return false;
		}
		
	}

	/**
	 * HashCode operation. 
	 * @return A hashcode of the data. 
	 */
	@Override
	public int hashCode() {
		return new HashCodeBuilder(97, 17).
				toHashCode();
	}
	
	/** 
	 * Get a list of SignalIndications by laneId.
	 * @param laneId The laneId to get indications for.
	 * @return The list of indications that apply to the given lane.
	 */
	public List<SignalIndication> getSignalsByLaneId(int laneId) {
		List<SignalIndication> ret = new LinkedList<SignalIndication>();
		for (SignalIndication ind : signals) {
			if (ind.getLaneId() == laneId) {
				ret.add(ind);
			}
		}
		
		return ret;
	}
	
	/** Get the list of SignalIndications */
	public List<SignalIndication> getSignals() {
		return signals;
	}
	
	/** Set the list of SignalIndications */
	public void setSignals(List<SignalIndication> signals) {
		this.signals = signals;
	}
}